package com.tpp.mapper;

import com.tpp.entity.*;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface UserMapper {

    //注解方式的mybatis
    //spring通过上面2个注解加上调用的service里面的@autowired注解，自动生成该接口的对象。

    @Select("select * from  tpp_user_info  ${where_condition}")
    User checkLogin(@Param("where_condition") String where_condition);



    @Select("SELECT Film_name,Score,Url \n" +
            "FROM film_info JOIN film_broadcast_info\n" +
            "ON film_info.Film_id=film_broadcast_info.Film_id\n" +
            "WHERE film_info.Film_play_status=1\n" +
            "ORDER BY film_info.Score DESC\n" +
            "LIMIT 5")
    List<FilmItemShow> findOnlineFilms();
    @Select("SELECT *\n" +
            "FROM cinema_info\n" +
            "ORDER BY Favorab_rate DESC\n" +
            "LIMIT 6")
    List<CinemaInfo> findCinemaRank();
    @Select("SELECT Film_name,Score,Url \n" +
            "FROM film_info JOIN film_broadcast_info\n" +
            "ON film_info.Film_id=film_broadcast_info.Film_id\n" +
            "WHERE film_info.Film_play_status=1\n" +
            "ORDER BY film_info.Score DESC\n"  )
    List<FilmItemShow> findAllOnlieFilms();
    @Select("SELECT * FROM cinema_info")
    List<CinemaInfo> findAllCinema();
    @Select("SELECT Cinema_name\n" +
            "FROM cinema_info JOIN hall_info\n" +
            "on cinema_info.Cinema_id=hall_info.Cinema_id\n" +
            "WHERE Hall_id=(\n" +
            "SELECT film_times.Hall_id\n" +
            "FROM hall_info JOIN film_times\n" +
            "ON hall_info.Hall_id=film_times.Hall_id\n" +
            "WHERE Film_times_id=#{0}\n" +
            ")\n")
    String findCinemaNameBytimesId(@Param("0") int time_id);
    @Select("SELECT film_times.* ,Hall_name\n" +
            "FROM film_times JOIN hall_info\n" +
            "on film_times.Hall_id=hall_info.Hall_id\n" +
            "WHERE Film_times_id=#{0}")
    FilmTime findTimeInfoByTimesId(@Param("0") int time_id);
    @Select("SELECT film_info.* ,Url\n" +
            "FROM film_info JOIN film_broadcast_info\n" +
            "ON film_info.Film_id=film_broadcast_info.Film_id\n" +
            "WHERE film_info.Film_id=(\n" +
            "SELECT Film_id\n" +
            "FROM film_times\n" +
            "WHERE Film_times_id=#{0}\n" +
            "            )")
    Film findFilmIfoByTimesId(@Param("0") int time_id);
    @Select("SELECT Telephone\n" +
            "FROM tpp_user_info\n" +
            "WHERE User_id=#{0}")
    String findPhonenumberByUesrId(@Param("0") int user_id);
    @Insert("insert into order_info values(#{Order_number}, #{Uesr_id}, #{Actual_money}," +
            " #{Film_times_id}, " + "#{Order_time})")
    int AddOrder(Order order);
    @Insert("insert into order_seat_info(Pos_x, Pos_y, Order_number) values(#{0}, #{1}, #{2})")
    int AddOrderSeat(@Param("0") int hang,@Param("1")int lie,@Param("2")String orderId);
    @Update("UPDATE film_times\n" +
            "SET Seat_info=#{0}\n" +
            "WHERE Film_times_id=#{1}")
    int  updateSeat(@Param("0") String seat,@Param("1") int time_id);
    @Select("SELECT Seat_info\n" +
            "FROM film_times\n" +
            "WHERE Film_times_id=#{0}")
    String findSeatInfoByTimesId1(@Param("0") int time_id);

    @Insert("insert into tpp_user_info(User_name,Telephone,User_pwd) values(#{0}, #{1}, #{2})")
    int AddUser(@Param("0") String userCode,@Param("1")String  userPwd,@Param("2")String phone);


    @Select("select * from  tpp_user_info ")
    List<User> getAllUser_wx();
    @Select("SELECT User_id\n" +
            "FROM tpp_user_info\n" +
            "WHERE User_name=#{0}\n")
    int findUserIdByUsername(@Param("0") String username);
}
